Skip to content

fix: Handle invalid Extension Settings#37

Merged
alexs-mparticle merged 2 commits into
developmentfrom
fix/SQDSDKS-7496-fix-empty-extensions
Jul 14, 2025
Merged

fix: Handle invalid Extension Settings#37
alexs-mparticle merged 2 commits into
developmentfrom
fix/SQDSDKS-7496-fix-empty-extensions

Conversation

@alexs-mparticle

Copy link
Copy Markdown
Collaborator

Summary

  • Handle cases where setting string may come back incorrectly, such as NONE or NULL.

Testing Plan

  • Using a sample app with local overrides, test different variations of invalid roktExtension settings.

This comment was marked as outdated.

Comment thread src/Rokt-Kit.js Outdated
function extractRoktExtensions(settingsString) {
var settings = settingsString ? parseSettingsString(settingsString) : [];

var settings = parseSettingsString(settingsString);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should still have the conditional. otherwise everyone immediately will start to see a console.error about there not being invalid json right?, right?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves resilience against invalid extension settings by logging parse errors and returning empty lists instead of throwing. It also adds tests to verify behavior for malformed inputs.

  • Changed parseSettingsString to catch JSON errors, log them, and return an empty array.
  • Updated extractRoktExtensions to handle undefined and null settings without throwing.
  • Added unit tests covering invalid setting strings.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
test/src/tests.js Added test cases for NONE, undefined, and null inputs.
src/Rokt-Kit.js Modified error handling in parseSettingsString and maintained loop logic in extractRoktExtensions.
Comments suppressed due to low confidence (2)

test/src/tests.js:1286

  • Consider adding a test for an empty string ('') input to cover another common invalid case.
                .extractRoktExtensions('NONE')

test/src/tests.js:1284

  • It may be valuable to assert that console.error is called when parsing invalid JSON to ensure the error logging path is covered.
        it('should handle invalid setting strings', () => {

Comment thread src/Rokt-Kit.js
return JSON.parse(settingsString.replace(/"/g, '"'));
} catch (error) {
throw new Error('Settings string contains invalid JSON');
console.error('Settings string contains invalid JSON');

Copilot AI Jul 14, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider including the original error object when logging JSON parse failures to provide more context, e.g., console.error('Settings string contains invalid JSON', error);.

Suggested change
console.error('Settings string contains invalid JSON');
console.error('Settings string contains invalid JSON', error);

Copilot uses AI. Check for mistakes.
Comment thread src/Rokt-Kit.js
@alexs-mparticle alexs-mparticle merged commit fff87ac into development Jul 14, 2025
4 checks passed
@alexs-mparticle alexs-mparticle deleted the fix/SQDSDKS-7496-fix-empty-extensions branch March 25, 2026 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants